package cn.phantom.interrrupt;

import java.util.concurrent.TimeUnit;

public class LockSupportDemo01 {
    static Object objectLock = new Object();

    public static void main(String[] args) {

        // wait和notify必须和synchronized一起使用
        new Thread(() -> {
            synchronized (objectLock) {
                System.out.println(Thread.currentThread().getName() + "\t" + "-----come in");
                try {
                    objectLock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "\t" + "------被唤醒");
            }
        }, "ti").start();

        try {
            TimeUnit.MILLISECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            synchronized (objectLock) {
                objectLock.notify();
                System.out.println(Thread.currentThread().getName() + "\t" + "------发出通知");
            }
        }, "t2").start();


    }
}
